package com.hk.aop;

import java.math.BigDecimal;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import com.hk.service.order.IContract;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hk.commons.ConstantPayment;
import com.hk.commons.ConstantRoute;
import com.hk.commons.entity.order.OrderInfo;
import com.hk.service.kyc.ICoupon;
import com.hk.service.order.IOrderInfo;
import com.hk.service.product.IProductInfo;

@Service
@Aspect
public class OrderAop {

	private Logger logger = LoggerFactory.getLogger(OrderAop.class);

	@Autowired
	IProductInfo productService;

	@Autowired
	IOrderInfo orderService;
	
	@Autowired
	ICoupon couponService;

	@Pointcut("execution(* com.hk.service.order.impl.OrderInfoImpl.add(..))")
	private void pointCutAddOrder() {

	}
 
	/**
	 * After 用户注册成功之后调用该方法, 增加1个推荐用户数
	 * 
	 * @param
	 */
	@AfterReturning(pointcut = "pointCutAddOrder()", returning = "returnValue")
	public Boolean pointCutAddOrder(JoinPoint point, Object returnValue) {

		logger.info("下单成功之后调用该方法 @AfterReturning：返回值为：={}", returnValue);

		Long orderId = (Long) returnValue;

		ExecutorService executor = Executors.newFixedThreadPool(1);

		Runnable task = new Runnable() {
			public void run() {
				//赠送卡券
				//sendCard(orderId);
			}

		};
		executor.execute(task);
		executor.shutdown();
		return true;
	}

}
